import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

import { svgBuilder } from "./src/components/icon/svg/index";
const pathResolve = (dir) => {
   return resolve(__dirname, '.', dir)
}
// https://vitejs.dev/config/
export default defineConfig(async () => ({
  plugins: [vue(),svgBuilder('./src/assets/icons/')],
  resolve:{
     '/@': pathResolve('./src/'),
     assets: pathResolve('./src/assets')
  },
  emptyOutDir: true,
  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  //
  // 1. prevent vite from obscuring rust errors
  clearScreen: false,
  // 2. tauri expects a fixed port, fail if that port is not available
  server: {
    port: 1420,
    strictPort: true,
    watch: {
      // 3. tell vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"],
    },
  },
  build: {
    rollupOptions: {
      chunkSizeWarningLimit: 15000,
      output: {
        manualChunks(id) {
          // 分包配置，配置完成自动按需加载
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
        },
      }
    }
  },
}));
